<template>
  <div class="swiper-container" :ref="someRef">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="img in someList" :key="img.id">
        <img :src="img.imgUrl" />
      </div>
    </div>
    <div class="swiper-pagination"></div>
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
  </div>
</template>

<script>
import Swiper from "swiper";
import "swiper/css/swiper.min.css";
export default {
  name: "Carousel",
  props: ["someList", "someRef"],
  watch: {
    someList: {
      handler(newVal, oldVal) {
        if (!newVal.length) {
          return;
        }

        this.$nextTick(() => {
          new Swiper(this.$refs[this.someRef], {
            spaceBetween: 0,
            centeredSlides: true,
            autoplay: {
              delay: 1000,
              disableOnInteraction: false,
            },
            pagination: {
              el: ".swiper-pagination",
              clickable: true,
            },
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
          });
        });
      },
      immediate: true,
    },
  },
};
</script>

<style lang="less" scoped>
</style>
